#pragma once
#include <QtWidgets/QOpenGLWidget>
#include <QPoint>
#include <QTimer>
#include <Display/camera.h>
#include <memory>
#include <SceneGraph/scene_graph.h>
using PhysLeo::Camera;

class GLwindow : public QOpenGLWidget {
	Q_OBJECT

public:
	explicit GLwindow(std::shared_ptr<PhysLeo::SceneGraph> scene_graph, QWidget *parent = nullptr) :QOpenGLWidget(parent), scene_graph_(std::move(scene_graph)), camera_(), last_pos_(), timer_(this) {
		connect(&timer_, SIGNAL(timeout()), this, SLOT(update()));
		timer_.setInterval(17);
		timer_.start();

        camera_.setPosition(glm::vec3(0, 0, 20));
        camera_.setFocusPosition(glm::vec3(0, 0, 0));
        camera_.setNearClip(0.01f);
        camera_.setFarClip(1.0e3f);
	}
	Camera* getCamera() { return &camera_; }

protected:
    void initializeGL() override;
    void paintGL() override;
    void resizeGL(int w, int h) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

public slots:												
void updateWindow() { 
    scene_graph_->updateDrawDataGraph();
}

private:
    std::shared_ptr<PhysLeo::SceneGraph> scene_graph_;
	Camera camera_;
	QPoint last_pos_;
	QTimer timer_;
};